<?#//v.3.1.1
#///////////////////////////////////////////////////////
#//  COPYRIGHT 2004 Phpauction.org ALL RIGHTS RESERVED//
#///////////////////////////////////////////////////////

require('../includes/config.inc.php');
include "loggedin.inc.php";
unset($ERR);

#// Create currencies array
$query = "SELECT id,valuta,symbol,ime FROM PHPAUCTIONXL_rates ORDER BY ime";
$res_ = @mysql_query($query);
if(!$res_)
{
	print "Error: $query<BR>".mysql_error();
	exit;
}
elseif(@mysql_num_rows($res_) > 0)
{
	while($row = mysql_fetch_array($res_))
	{
		$CURRENCIES[$row[id]] = "$row[symbol]&nbsp;$row[ime]&nbsp($row[valuta]) ";
		$CURRENCIES_SYMBOLS[$row[id]] = "$row[symbol]";
	}
}


#//
if($_POST[action] == "update" && phpa_securepost($_POST))
{
	#// Data check
	if(empty($_POST[defaultcurrency]) ||
	empty($_POST[moneyformat]) ||
	empty($_POST[moneysymbol]))
	{
		$ERR = $ERR_047;
		$SETTINGS = $_POST;
	}
	elseif(!empty($_POST[moneydecimals]) && !ereg("^[0-9]+$",$_POST[moneydecimals]))
	{
		$ERR = $ERR_051;
		$SETTINGS = $_POST;
	}
	else
	{
		#// Update database
		$query = "update PHPAUCTIONXL_settings set currency='".addslashes($CURRENCIES_SYMBOLS[$_POST[defaultcurrency]])."',
								          moneyformat=$_POST[moneyformat],
								          moneydecimals=".intval($_POST[moneydecimals]).",
								          moneysymbol=$_POST[moneysymbol]";
		$res = @mysql_query($query);
		if(!$res)
		{
			print "Error: $query<BR>".mysql_error();
			exit;
		}
		else
		{
			$ERR = $MSG_553;
			$SETTINGS = $_POST;
		}
	}
	
	if(is_array($_POST[othercurrencies]))
	{
		@mysql_query("DELETE FROM PHPAUCTIONXL_currencies");
		while(list($k,$v) = each($_POST[othercurrencies]))
		{
			$query = "INSERT INTO PHPAUCTIONXL_currencies VALUES (NULL,'$v')";
			//print $query;
			$res = @mysql_query($query);
			if(!$res)
			{
				print "Error: $query<BR>".mysql_error();
				exit;
			}
		}
	}
}
#//
$query = "SELECT * FROM PHPAUCTIONXL_settings";
$res = @mysql_query($query);
if(!$res)
{
	print "Error: $query<BR>".mysql_error();
	exit;
}
elseif(mysql_num_rows($res) > 0)
{
	$SETTINGS = mysql_fetch_array($res);
}


$OTHERCURRENCIES = array();
$query = "SELECT * FROM PHPAUCTIONXL_currencies";
$res = @mysql_query($query);
if(!$res)
{
	print "Error: $query<BR>".mysql_error();
	exit;
}
elseif(mysql_num_rows($res) > 0)
{
	while($row = mysql_fetch_array($res))
	{
		$OTHERCURRENCIES[$row[id]] = $row[currency];
	}
}



?>
<HEAD>

<SCRIPT Language=Javascript>
function window_open(pagina,titulo,ancho,largo,x,y){
	
	var Ventana= 'toolbar=0,location=0,directories=0,scrollbars=1,screenX='+x+',screenY='+y+',status=0,menubar=0,resizable=0,width='+ancho+',height='+largo;
	open(pagina,titulo,Ventana);
	
}
</SCRIPT>
<link rel='stylesheet' type='text/css' href='style.css' />
<link href="css/main.css" rel="stylesheet" type="text/css">
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" link="#0066FF" vlink="#666666" alink="#000066" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0" class="titulo">
        <tr> 
          <td class="icono"><img src="images/pref_icon.gif" width="28" height="28"></td>
          <td class="breadcrumbs"><p><span><?=$MSG_25_0008?></span>&nbsp;&gt;&gt;&nbsp;<?=$MSG_5004?></p></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td align="center" valign="middle">&nbsp;</td>
  </tr>
    <tr> 
    <td align="center" valign="middle">
<TABLE BORDER=0 WIDTH=100% CELLPADDING=0 CELLSPACING=0 BGCOLOR="#FFFFFF">
<TR>
<TD align="center">
	<BR>
	<FORM NAME=conf ACTION=currency.php METHOD=POST>
		<TABLE WIDTH="95%" BORDER="0" CELLSPACING="0" CELLPADDING="0" class="base">
			<TR>
				<TD ALIGN=CENTER class=title>
					<p><? print $MSG_076; ?></p>
				</TD>
			</TR>
			<TR>
				<TD>
					<TABLE WIDTH=100% ALIGN="CENTER" CELLPADDING=0 cellspacing="0" style="border:1px solid #ccc;">
					<?
					if($ERR != "")
					{
					 ?>
						<TR BGCOLOR=yellow>
						 <TD class=error COLSPAN="2">
						<p> <? print $ERR; ?></p>
						 </TD>
					  </TR>
					   <?
					}
					?>
						<TR VALIGN="TOP">
							<TD WIDTH=173 HEIGHT="31" class="gris lineV">
								<p class="blue"><?=$MSG_5008;?></p>
						  </TD>
							<TD HEIGHT="31" WIDTH="459" class="gris">
							<SELECT NAME=defaultcurrency>
							<OPTION VALUE=""></OPTION>
							<?
							reset($CURRENCIES);
							while(list($k,$v) = each($CURRENCIES))
							{print "$k, $SETTINGS[currency]<br>";
							?>
								<OPTION VALUE="<?=$k?>" <?if($CURRENCIES_SYMBOLS[$k] == $SETTINGS[currency]) print " SELECTED"?>><?=$v?></OPTION>
							<?
							}
							?>
							</SELECT>
						        <BR>
						<?print $MSG_AJAX_ADMIN_CURRENCY_NOTE; ?>
						
						
							</TD>
						</TR>

						
						<TR VALIGN="TOP">
							<TD WIDTH=173 HEIGHT="31" class="lineV">
								<p class="blue"><?=$MSG_544;?></p>
						  </TD>
							<TD HEIGHT="31" WIDTH="459">
								<INPUT TYPE="radio" NAME="moneyformat" VALUE="1"
							<? if($SETTINGS[moneyformat] == 1) print " CHECKED";?>
							>
								
								<?=$MSG_545;?>
								<BR>
								<INPUT TYPE="radio" NAME="moneyformat" VALUE="2"
							<? if($SETTINGS[moneyformat] == 2) print " CHECKED";?>
							>
								
								<?=$MSG_546;?>
						  </TD>
						</TR>
		
								<INPUT TYPE=hidden NAME=moneydecimals VALUE="2" >
					

								<INPUT TYPE="hidden" NAME="moneysymbol" VALUE="2" >
			
						<TR>
							<TD WIDTH=173 class="lineV">
								<INPUT TYPE="hidden" NAME="action" VALUE="update" /> <INPUT TYPE="hidden" NAME="security" VALUE="<?php echo $_SESSION['security'];?>" />
								<INPUT TYPE="hidden" NAME="id" VALUE="<?=$id?>">
							</TD>
							<TD WIDTH="459">
								<INPUT TYPE="submit" NAME="act" VALUE="<? print $MSG_530; ?>" class="action">
							</TD>
						</TR>
						<TR>
							<TD WIDTH=173></TD>
							<TD WIDTH="459"> </TD>
						</TR>
					</TABLE>
				</TD>
			</TR>
		</TABLE>
		</FORM>
</TR>
</TABLE>

<!-- Closing external table (header.php) -->
</TD>
</TR>
</TABLE>

</TD>
</TR>
</TABLE>
</BODY>
</HTML>